<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="mini"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="" prop="stage">
        <!-- <el-select
          v-model="queryParams.stage"
          placeholder="项目状态"
          clearable
          style="width: 240px"
        >
          <el-option :key="2" label="待提交方案" :value="2" />
          <el-option :key="3" label="已提交方案" :value="3" />
        </el-select> -->

        <el-button
          :type="item.value == queryParams.stage ? 'primary' : 'default'"
          size="mini"
          @click="searchStage(item.value)"
          v-for="item in stageOptions"
          :key="item.value"
          >{{ item.label }}</el-button
        >
      </el-form-item>
      <!-- <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item> -->
    </el-form>

    <el-table v-loading="loading" :data="projectList">
      <el-table-column label="商机编码" prop="code" width="120" />
      <el-table-column label="客户名称" prop="custormer" width="120" />

      <el-table-column label="项目名称" prop="projectName" width="180" />

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            v-if="scope.row.stage == 2"
            type="text"
            @click="toDetail(scope.row, 'solution')"
          >
            提交解决方案
          </el-button>

          <template v-else>
            <!-- <el-button size="mini" type="text" @click="handleView(scope.row)">
              查看解决方案
            </el-button> -->
            <el-button
              size="mini"
              type="text"
              @click="toDetail(scope.row, 'asign')"
            >
              选择签约模式
            </el-button>
          </template>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
// import { getprojectList } from "@/api/business/index";
import { getProjectStatusList } from "@/api/project/index";

import {
  budgetFundOptions,
  sourceOptions,
  stageOptions,
  swotOptions,
} from "@/constant/index";

export default {
  name: "Role",
  data() {
    return {
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stage: 2,
      },
      // 数据列表
      projectList: [{}],
      stageOptions: [
        {
          label: "待提交方案",
          value: 2,
        },
        {
          label: "已提交方案",
          value: 3,
        },
      ],
    };
  },
  components: {},
  created() {
    this.getList();
  },
  filters: {
    swotFilter(value) {
      if (!value) return "";
      return swotOptions.find((item) => item.value == value).label;
    },
  },
  methods: {
    getList() {
      this.loading = true;

      getProjectStatusList(this.queryParams).then((response) => {
        this.projectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    toDetail(row) {
      this.$router.push(
        `/solution/detail?boId=${row.boId}&projectId=${row.id}`
      );
    },

    handleView(row) {
      this.$router.push(
        `/solution/detail?boId=${row.boId}&projectId=${row.id}`
      );
    },
    handleEdit(row) {
      this.$router.push(
        `/solution/detail?boId=${row.boId}&projectId=${row.id}`
      );
    },

    handleDelete(row) {
      this.$confirm("确定删除商机吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {})
        .catch(() => {});
    },

    /** 修改按钮操作 */
    handleUpdate() {},
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
